package jmine.tec.script.persistent.diagnostician;

import java.util.ArrayList;
import java.util.List;

import jmine.tec.script.persistent.ScriptController;
import jmine.tec.script.persistent.dao.ScriptDAO;
import jmine.tec.script.persistent.domain.Script;
import jmine.tec.script.persistent.domain.enumx.BaseScriptPurposeIdentifier;
import bancosys.tec.rtm.diagnostician.Diagnostician;
import bancosys.tec.rtm.diagnostician.GenericDiagnosticianCase;

/**
 * DiagnosticianCase que executa os diagnosticadores existentes no banco de dados.
 * 
 * @author Rafael Volpato
 * @date May 12, 2011
 */
public class ScriptDiagnosticianCase extends GenericDiagnosticianCase {

    private final ScriptController controller;

    /**
     * Construtor.
     * 
     * @param controller {@link ScriptController}
     */
    public ScriptDiagnosticianCase(ScriptController controller) {
        this.controller = controller;
    }

    /**
     * Retorna todos os {@link ScriptDiagnostician} existentes no banco de dados.
     * 
     * @return todos os {@link ScriptDiagnostician} existentes no banco de dados
     */
    public List<? extends Diagnostician> getDiagnosticiansListOfSystemInDebugMode() {
        ScriptDAO dao = this.controller.getDAOFactory().getDAOByClass(ScriptDAO.class);

        List<Diagnostician> sds = new ArrayList<Diagnostician>();
        List<Script> scripts = dao.findByPurpose(BaseScriptPurposeIdentifier.DIAGNOSIS.name());
        for (Script s : scripts) {
            sds.add(new ScriptDiagnostician(this.controller, s.getMnemonico(), s.getDescricao()));
        }

        return sds;
    }
}
